package com.fyd.mybatis.binding;

import com.fyd.mybatis.session.SqlSession;

import java.lang.reflect.Proxy;
import java.util.Map;

/**
 * @author fanyudong
 * @date 2025/6/3
 * @description 映射器代理工厂
 * @copyright 2025  35岁财富自由公司. All rights reserved.
 */
public class MapperProxyFactory<T> {

    // 给哪一个接口做代理
    private  final Class<T> mapperInterface;


    public MapperProxyFactory(Class<T> mapperInterface) {
        this.mapperInterface = mapperInterface;
    }

    public T newInstance(SqlSession sqlSession){
        MapperProxy<T> mapperProxy = new MapperProxy<>(sqlSession,mapperInterface);
        return (T)Proxy.newProxyInstance(mapperInterface.getClassLoader()
                , new Class[]{mapperInterface}, mapperProxy);
    }
}
